var $ = require("../../utils/Ajax.js");
function PrivacySetting(that){
  $.Ajax("api/userSet","POST",{
    isInvisible: that.data.isInvisible_,
    isInvisibleNickName: that.data.isInvisibleNickName_,
    isInvisibleBirthday: that.data.isInvisibleBirthday_,
    isInvisibleBirthday0: that.data.isInvisibleBirthday0_,
    isInvisibleEmotion: that.data.isInvisibleEmotion_,
    isInvisibleConstellation: that.data.isInvisibleConstellation_,
    isInvisibleHometown: that.data.isInvisibleHometown_,
    isInvisibleProfession: that.data.isInvisibleProfession_,
    isInvisibleShool: that.data.isInvisibleShool_
  },function(res){
    console.log(res)
  })
}
Page({
  data: {
    isInvisibleNickName: true,
    isInvisibleNickName_: 1,
    isInvisibleBirthday: true,
    isInvisibleBirthday_: 1,
    isInvisibleEmotion: true,
    isInvisibleEmotion_: 1,
    isInvisibleBirthday0: true,
    isInvisibleBirthday0_: 1,
    isInvisibleConstellation: true,
    isInvisibleConstellation_: 1,
    isInvisibleHometown: true,
    isInvisibleHometown_: 1,
    isInvisibleProfession: true,
    isInvisibleProfession_: 1,
    isInvisibleShool: true,
    isInvisibleShool_: 1,

    // 控制全部
    All: true,

    // 控制隐身
    isInvisible: true,
    isInvisible_: 1
  },

  onShow: function(){
    var UserSet = wx.getStorageSync('UserInfor').user_set;
    if(UserSet.isInvisible){
      this.setData({
        isInvisible: true,
        isInvisible_: 1
      })
    }else{
      this.setData({
        isInvisible: false,
        isInvisible_: 0
      })
    }
    if (UserSet.isInvisibleNickName){
      this.setData({
        isInvisibleNickName: true,
        isInvisibleNickName_: 1
      })
    }else{
      this.setData({
        isInvisibleNickName: false,
        isInvisibleNickName_: 0
      })
    }
    if (UserSet.isInvisibleBirthday){
      this.setData({
        isInvisibleBirthday: true,
        isInvisibleBirthday_: 1
      })
    }else{
      this.setData({
        isInvisibleBirthday: false,
        isInvisibleBirthday_: 0
      })
    }
    if (UserSet.isInvisibleBirthday0){
      this.setData({
        isInvisibleBirthday0: true,
        isInvisibleBirthday0_: 1
      })
    }else{
      this.setData({
        isInvisibleBirthday0: false,
        isInvisibleBirthday0_: 0
      })
    }
    if (UserSet.isInvisibleEmotion) {
      this.setData({
        isInvisibleEmotion: true,
        isInvisibleEmotion_: 1
      })
    } else {
      this.setData({
        isInvisibleEmotion: false,
        isInvisibleEmotion_: 0
      })
    }
    if (UserSet.isInvisibleConstellation) {
      this.setData({
        isInvisibleConstellation: true,
        isInvisibleConstellation_: 1
      })
    } else {
      this.setData({
        isInvisibleConstellation: false,
        isInvisibleConstellation_: 0
      })
    }
    if (UserSet.isInvisibleHometown) {
      this.setData({
        isInvisibleHometown: true,
        isInvisibleHometown_: 1
      })
    } else {
      this.setData({
        isInvisibleHometown: false,
        isInvisibleHometown_: 0
      })
    }
    if (UserSet.isInvisibleProfession) {
      this.setData({
        isInvisibleProfession: true,
        isInvisibleProfession_: 1
      })
    } else {
      this.setData({
        isInvisibleProfession: false,
        isInvisibleProfession_: 0
      })
    }
    if (UserSet.isInvisibleShool) {
      this.setData({
        isInvisibleShool: true,
        isInvisibleShool_: 1
      })
    } else {
      this.setData({
        isInvisibleShool: false,
        isInvisibleShool_: 0
      })
    }
    if (UserSet.isInvisibleNickName && UserSet.isInvisibleBirthday && UserSet.isInvisibleBirthday0 && UserSet.isInvisibleEmotion && UserSet.isInvisibleConstellation && UserSet.isInvisibleHometown && UserSet.isInvisibleProfession && UserSet.isInvisibleShool) {
      this.setData({
        All: true,
        All_: 1
      })
    } else {
      this.setData({
        All: false,
        All_: 0
      })
    }
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "隐私设置"
    })
  },

  isInvisibleNickName: function(e){
    var isInvisibleNickName = e.detail.value;
    if (isInvisibleNickName){
      this.setData({
        isInvisibleNickName_: 1
      })
    }else{
      this.setData({
        isInvisibleNickName_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleBirthday: function(e){
    var isInvisibleBirthday = e.detail.value;
    if (isInvisibleBirthday) {
      this.setData({
        isInvisibleBirthday_: 1
      })
    } else {
      this.setData({
        isInvisibleBirthday_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleEmotion: function(e){
    var isInvisibleEmotion = e.detail.value;
    if (isInvisibleEmotion) {
      this.setData({
        isInvisibleEmotion_: 1
      })
    } else {
      this.setData({
        isInvisibleEmotion_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleBirthday0: function(e){
    var isInvisibleBirthday0 = e.detail.value;
    if (isInvisibleBirthday0) {
      this.setData({
        isInvisibleBirthday0_: 1
      })
    } else {
      this.setData({
        isInvisibleBirthday0_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleConstellation: function(e){
    var isInvisibleConstellation = e.detail.value;
    if (isInvisibleConstellation) {
      this.setData({
        isInvisibleConstellation_: 1
      })
    } else {
      this.setData({
        isInvisibleConstellation_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleHometown: function(e){ 
    var isInvisibleHometown = e.detail.value;
    if (isInvisibleHometown) {
      this.setData({
        isInvisibleHometown_: 1
      })
    } else {
      this.setData({
        isInvisibleHometown_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleProfession: function(e){ 
    var isInvisibleProfession = e.detail.value;
    if (isInvisibleProfession) {
      this.setData({
        isInvisibleProfession_: 1
      })
    } else {
      this.setData({
        isInvisibleProfession_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisibleShool: function(e){
    var isInvisibleShool = e.detail.value;
    if (isInvisibleShool) {
      this.setData({
        isInvisibleShool_: 1
      })
    } else {
      this.setData({
        isInvisibleShool_: 0
      })
    }
    PrivacySetting(this);
  },
  All: function(e){ 
    var All = e.detail.value;
    if (All) {
      this.setData({
        isInvisibleNickName: true,
        isInvisibleNickName_: 1,
        isInvisibleBirthday: true,
        isInvisibleBirthday_: 1,
        isInvisibleEmotion: true,
        isInvisibleEmotion_: 1,
        isInvisibleBirthday0: true,
        isInvisibleBirthday0_: 1,
        isInvisibleConstellation: true,
        isInvisibleConstellation_: 1,
        isInvisibleHometown: true,
        isInvisibleHometown_: 1,
        isInvisibleProfession: true,
        isInvisibleProfession_: 1,
        isInvisibleShool: true,
        isInvisibleShool_: 1
      })
    } else {
      this.setData({
        isInvisibleNickName: false,
        isInvisibleNickName_: 0,
        isInvisibleBirthday: false,
        isInvisibleBirthday_: 0,
        isInvisibleEmotion: false,
        isInvisibleEmotion_: 0,
        isInvisibleBirthday0: false,
        isInvisibleBirthday0_: 0,
        isInvisibleConstellation: false,
        isInvisibleConstellation_: 0,
        isInvisibleHometown: false,
        isInvisibleHometown_: 0,
        isInvisibleProfession: false,
        isInvisibleProfession_: 0,
        isInvisibleShool: false,
        isInvisibleShool_: 0
      })
    }
    PrivacySetting(this);
  },
  isInvisible: function(e){ 
    var isInvisible = e.detail.value;
    if (isInvisible) {
      this.setData({
        isInvisible_: 1
      })
    } else {
      this.setData({
        isInvisible_: 0
      })
    }
    PrivacySetting(this);
  }
})